package io.easyspring.invitation.core;

import io.easyspring.invitation.core.events.InvitationSendSuccessEvent;
import io.easyspring.invitation.core.support.EasyInvitation;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 邀请信息的事件发送器
 *
 * @author summer
 * @version 2.0.0-RELEASE
 * DateTime 2019-06-22 16:14
 */
@Component
public class InvitationEventPublisher {

    /**
     * 注入程序上下文环境
     */
    @Resource
    private ApplicationContext applicationContext;

    /**
     * 封装注册成功事件的发送方法
     *
     * @param source 事件最初发生的对象本身
     * @param invitation 邀请信息对象
     * Author summer
     * Version 2.0.0-RELEASE
     * DateTime 2019-06-22 16:14
     */
    public <T extends EasyInvitation> void publishInvitationSendSuccessEvent(Object source, T invitation){
        // 创建邀请信息发送成功事件
        InvitationSendSuccessEvent sendInvitationSuccessEvent = new InvitationSendSuccessEvent(source, invitation);
        // 发送事件
        applicationContext.publishEvent(sendInvitationSuccessEvent);
    }
}
